package com.bdqn.t320.ch12.repository;

import com.bdqn.t320.ch12.entity.Right;
import com.bdqn.t320.ch12.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface RightRepository extends JpaRepository<Right, String> {

    //public List<Right> findRightsByRolesOrderByRightCode(Role role); //根据角色查询权限

    @Query(value = "select t.right_code,t.right_parent_code,t.right_text,t.right_tip,t.right_type,t.right_url from sys_right t", nativeQuery = true)
    public List<Right> getRightAll();


    @Query(value = "select * from sys_right r where r.right_code in(select rf_right_code from sys_role_right where rf_role_id = (select usr_role_id from sys_user where usr_id=?1))", nativeQuery = true)
    public List<Right> getRightByUsrId(Long usrId);


}
